#include <iostream>
#include <string>
#include <cstring> // string.h
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(){
    std::string message ="Father ,I am child";
         int pipefd[2];
    int n =pipe(pipefd);
    pid_t id = fork();
if(id==0)
{
    int cnt =10;
    char save_read [1024];
    while(cnt--){
        cnt--;
    sleep(1);
    close(pipefd[1]);
   ssize_t n = read(pipefd[0] ,save_read, sizeof(save_read) - 1);
   
  if(n>0){
            save_read[n]='\0';
            std::cout<<"child::"<<save_read<<std::endl;
            }
            else if(n==0){
                std::cout<<"SON EXITED"<<std::endl;
                break;
            }
    
    }
    close(pipefd[0]);

}
int cnt=10;
while(cnt){
    cnt--;
    sleep(1);
close(pipefd[0]);
write(pipefd[1], message.c_str(), message.size());
std::cout<<"father send meassage"<<std::endl;
}
close(pipefd[1]);
}   